package com.qqt.csr.archive.controller;

import com.qqt.csr.archive.request.ArchiveConversationPageQueryRequest;
import com.qqt.csr.archive.request.ArchiveHistoryMessageRequest;
import com.qqt.csr.archive.response.ArchiveConversationDetailResponse;
import com.qqt.csr.archive.response.ArchiveConversationResponse;
import com.qqt.csr.archive.response.ArchiveMessageResponse;
import com.qqt.csr.archive.service.ArchiveConversationService;
import com.qqt.csr.common.vo.resp.ObjectResponse;
import com.qqt.csr.common.vo.resp.PageResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotBlank;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: yang hao
 * @Date: 2024/11/28 8:58
 * @Description: 归档会话 数据查询接口
 **/
@Slf4j
@Tag(name = "归档会话 数据查询服务")
@RestController
@RequestMapping("/archive/conversation")
public class ArchiveConversationController {

    @Autowired
    private ArchiveConversationService archiveConversationService;

    @PostMapping("/page")
    @Operation(summary = "归档会话 分页查询")
    public PageResponse<ArchiveConversationResponse> page(@RequestBody ArchiveConversationPageQueryRequest request) {
       return archiveConversationService.page(request);
    }

    @GetMapping("/detail/{id}")
    @Operation(summary = "归档会话 详情查询 归档记录id")
    public ObjectResponse<ArchiveConversationDetailResponse> detail(@PathVariable("id") @NotBlank(message = "会话id不能为空") String id) {
        return ObjectResponse.success(archiveConversationService.detail(id));
    }

    @GetMapping("/detailByConversationId/{conversationId}")
    @Operation(summary = "归档会话 详情查询 会话id")
    public ObjectResponse<ArchiveConversationDetailResponse> detailByConversationId(@PathVariable("conversationId") @NotBlank(message = "会话id不能为空") String conversationId) {
        return ObjectResponse.success(archiveConversationService.detailByConversationId(conversationId));
    }

    @PostMapping("/historyMessage")
    @Operation(summary = "归档会话 历史消息查询")
    public ObjectResponse<List<ArchiveMessageResponse>> historyMessage(@RequestBody @Validated ArchiveHistoryMessageRequest request) {
        return ObjectResponse.success(archiveConversationService.historyMessage(request.getConversationId(), request.getVisitorId(), request.getChannelId(), request.getUserId(), request.getSource()));
    }

}
